import java.util.Random;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 周斌
 * Date: 2023-10-30
 * Time: 21:43
 */
public class Test {
    public static void main(String[] args) {
        //猜数字
        //1.生成1-100的随机数
        //2.玩家输入的数与生成的随机数进行比较
        int num = 0;
        Scanner scanner = new Scanner(System.in);
        //系统随机生成1-100的数
        Random random = new Random();
        int Random = random.nextInt(100);//此时生成的是[0-100)半开半闭
        Random += 1;//我们需要的是1-100的整数
        int count = 3;//记录猜的次数
        while(count != 0) {
            System.out.println("请输入1-100的数字:>");
             num = scanner.nextInt();
            count--;
            //猜大小
            if(num < Random) {
                System.out.println("猜小了");
            } else if(num > Random) {
                System.out.println("猜大了");
            }
            else {
                System.out.println("猜对了");
                break;
            }
        }
        if(count == 0 && Random != num){
            System.out.println("次数用完了，游戏失败");
        }
    }
}
